package com.atguigu.service.Impl;

import com.alibaba.dubbo.container.page.Page;
import com.atguigu.dao.BaseDao;
import com.atguigu.dao.DictDao;
import com.atguigu.dao.UserFollowDao;
import com.atguigu.entity.UserFollow;
import com.atguigu.service.UserFollowService;
import com.atguigu.vo.UserFollowVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @title：
 * @author：Yu
 * @create：2023-02-25 10:50
 * @description：
 */
@DubboService
public class UserFollowServiceImpl extends BaseServiceImpl<UserFollow> implements UserFollowService {
    @Autowired
    private UserFollowDao userFollowDao;
    @Autowired
    private DictDao dictDao;

    @Override
    public BaseDao<UserFollow> getBaseDao() {
        return userFollowDao;
    }

    @Override
    public void follow(Long houseId, Long userId) {
        UserFollow userFollow = new UserFollow();
        userFollow.setUserId(userId);
        userFollow.setHouseId(houseId);
        userFollowDao.insert(userFollow);
    }

    @Override
    public UserFollow findUser(Long houseId, Long userId) {
        return userFollowDao.findUser(houseId, userId);
    }

    @Override
    public PageInfo<UserFollowVo> findList(Integer pageNum, Integer pageSize, Long userId) {
        PageHelper.startPage(pageNum, pageSize);
        List<UserFollowVo> page = userFollowDao.findList(userId);
        for (UserFollowVo userFollowVo : page) {
            userFollowVo.setHouseTypeName(dictDao.findById(userFollowVo.getHouseTypeId()).getName());
            userFollowVo.setFloorName(dictDao.findById(userFollowVo.getFloorId()).getName());
            userFollowVo.setDirectionName(dictDao.findById(userFollowVo.getDirectionId()).getName());
        }
        return new PageInfo<UserFollowVo>(page, 3);
    }
}
